const mysql = require("mysql");

//! 连接池
let pool = mysql.createPool({
  host: "localhost", //! 连接的服务(代码托管到线上后，需改为内网IP，而非外网)
  port: 3306, //? mysql服务运行的默认端口
  database: "appdb", //todo 选择的库
  user: "root", //? 用户名
  password: "jiubei0128", //! 用户密码
});

//! 对数据库进行增删改查操作的基础
const query = (sql, callback) => {
  pool.getConnection((err, connection) => {
    connection.query(sql, (err, rows) => {
      callback(err, rows);
      connection.release(); // todo 中断链接
    });
  });
};

exports.query = query;
